using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Resources;

namespace LANLauncher
{
	public class StringLocaliser
	{
		public static string language;

		public static Dictionary<string, string> manualLocalisations;

		static StringLocaliser()
		{
			StringLocaliser.language = "ENG";
			StringLocaliser.manualLocalisations = new Dictionary<string, string>();
		}

		public StringLocaliser()
		{
		}

		public static string LocaliseString(string _str, bool _allowUnlocalised)
		{
			string str;
			if (_str.Length == 0)
			{
				return "";
			}
			string str1 = string.Concat("LANLauncher.Strings", StringLocaliser.language, ".resources");
			Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(str1);
			if (manifestResourceStream == null)
			{
				manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("LANLauncher.StringsENG.resources");
				if (manifestResourceStream == null)
				{
					if (_allowUnlocalised)
					{
						return _str;
					}
					return "????";
				}
			}
			foreach (DictionaryEntry dictionaryEntry in new ResourceReader(manifestResourceStream))
			{
				if (_str != dictionaryEntry.Key.ToString())
				{
					continue;
				}
				str = dictionaryEntry.Value.ToString();
				return str;
			}
			Dictionary<string, string>.Enumerator enumerator = StringLocaliser.manualLocalisations.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					KeyValuePair<string, string> current = enumerator.Current;
					if (current.Key != _str)
					{
						continue;
					}
					str = current.Value;
					return str;
				}
				if (_allowUnlocalised)
				{
					return _str;
				}
				return "xx";
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			//return str;
		}
	}
}